package com.lr.api.controller.v1;

import com.lr.domain.entity.Departments;
import com.lr.service.DepartmentService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    private DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @GetMapping("/findDep")
    public ResponseEntity<?> findDepartment(){
        List<Departments> department = departmentService.findDep();
        return ResponseEntity.ok(department);
    }

    @PostMapping("/createDep")
    public ResponseEntity<?> createDepartment(Departments department){
        departmentService.createDepartment(department);
        return ResponseEntity.ok("添加成功");
    }

    @DeleteMapping("/deleteDep")
    public ResponseEntity<?> deleteDepartment(Integer id){
        departmentService.deleteDepartment(id);
        return ResponseEntity.ok("删除成功");
    }

    @PutMapping("/updateDep")
    public ResponseEntity<?> updateDepartment(Departments department){
        departmentService.updateDepartment(department);
        return ResponseEntity.ok("修改成功");
    }

    @GetMapping("/findDepAndEmployment")
    public ResponseEntity<?> findDepAndEmployment(){
        List<Departments> departments = departmentService.oneToNum();
        return ResponseEntity.ok(departments);
    }
}
